#include<bits/stdc++.h>
#define sd(n) scanf("%d",&n) 
#define sld(n) scanf("%lld",&n)
#define pd(n) printf("%d", (n))
#define pld(n) printf("%lld", n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
const int N=2e5;
#define INF 0x7fffffff
typedef long long int ll;
using namespace std;
//----------------------------------------------------------------------------//

void solve()
{
	string s1,s2;
	int n;
	sd(n);
	cin>>s1;
	if(n&1)
	{
		int num=1;
		int mid=(n>>1);
		int mid2=mid;
		while(mid2-1>=0&&s1[mid2-1]==s1[mid2]) num++,mid2--;
		mid2=mid;
		while(mid2+1<n&&s1[mid2]==s1[mid2+1]) num++,mid2++;
		pd(num);puts("");
	}
	else
	{
		int num=2;
		int r=(n>>1);
		int l=r-1;
		while(l-1>=0&&s1[l-1]==s1[l]) num++,l--;
		while(r+1<n&&s1[r+1]==s1[r]) num++,r++;
		pd(num);puts("");
	}
}

int main()
{
	int T;
	sd(T);
	while (T--)
	{
		solve();
	}
	return 0;
}